package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.TTcCitySearchVo;
import com.zhijian.medical.entity.vo.response.TTcCityVo;
import com.zhijian.medical.service.TTcCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author HCG
 * @version 1.0
 * @date 2021/10/25
 */
@Slf4j
@Controller
@Api(tags = "省市区")
public class TcCityController {

    @Autowired
    private TTcCityService tTcCityService;

    /**
     * 目录树状数据
     *
     * @return
     */
    @Response
    @GetMapping("/tc/city/tree")
    @ApiOperation("目录树状数据")
    public List<TTcCityVo> treeList() {
        return tTcCityService.renderTreeList();
    }

    /**
     * 根据父级获取子级，获取省级parentId填1
     *
     * @return
     */
    @Response
    @GetMapping("/tc/city/{parentId}")
    @ApiOperation("根据父级获取子级，获取省级parentId填1")
    public List<TTcCityVo> selectByParentId(@PathVariable("parentId") Long parentId) {
        return tTcCityService.selectList(TTcCitySearchVo.builder().parentId(parentId).build());
    }
}
